package yue.shen.android.demo.adapter;

import androidx.annotation.Nullable;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

public class SwipeRefreshHelper {
    private final SwipeRefreshLayout swipeRefresh;
    private SwipeRefreshListener listener;

    public static SwipeRefreshHelper createSwipeRefreshHelper(SwipeRefreshLayout swipeRefresh) {
        return new SwipeRefreshHelper(swipeRefresh);
    }

    private SwipeRefreshHelper(@Nullable SwipeRefreshLayout swipeRefresh) {
        this.swipeRefresh = swipeRefresh;
        init();
    }

    private void init() {
        swipeRefresh.setColorSchemeResources(android.R.color.holo_orange_dark
                , android.R.color.holo_green_dark, android.R.color.holo_blue_dark);
        swipeRefresh.setOnRefreshListener(() -> {
            if (listener != null) {
                listener.onRefresh();
            }
        });
    }

    public void setListener(SwipeRefreshListener listener) {
        this.listener = listener;
    }

    public interface SwipeRefreshListener {
        void onRefresh();
    }

}
